<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Core.DAL.tSite_Link>>" %>

<asp:Content ID="cHead" ContentPlaceHolderID="cphHead" runat="server">
    <% this.Page.Title = (string)ViewData["PageTitle"]; %>
</asp:Content>

<asp:Content ID="cJScripts" ContentPlaceHolderID="cphJScripts" runat="server">
   <% if ((UserType)ViewData["UserType"] == UserType.Administrator){  %>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".lien").mouseenter(function () {
                $(this).find(".adminTools").show();
            }).mouseleave(function () {
                $(this).find(".adminTools").hide();
            });

            $(".deleteItem").colorbox({ width: "400px", height: "150px", iframe: true, title: "Supprimer ce lien" });
            $(".validateLink").colorbox({ width: "400px", height: "150px", iframe: true, title: "Valider ce lien" });
        });

        function DeleteLink(LID) {
            $.ajax({
                type: "POST",
                url: "/Liens/Delete",
                data: 'ID=' + LID,
                success: function(returnMessage) {
                    $(".js-link" + LID).hide("fast");
                }
            });
        }

        function ValidateLink(LID){
            $.ajax({
                type: "POST",
                url: "/Liens/Validate",
                data: 'ID=' + LID,
                success: function (returnMessage) {
                    $(".js-link" + LID).removeClass("inValide", 1000);
                }
            });
        }
    </script>
    <%} %>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#infoBread a').colorbox({ width: "400px", height: "<%= (!User.Identity.IsAuthenticated) ? 490 : 350 %>px", scrolling: false, iframe: true, title: "Proposer un lien" });
        });
    </script>
</asp:Content>

<asp:Content ID="cBreadCrumb" ContentPlaceHolderID="cphBreadCrumb" runat="server">
    <div id="infoBread">
        <%= Html.ActionLink("Proposer un lien", "Create", new { controller = "Liens" }, new { title = "Proposer un lien" })%>
    </div>
</asp:Content>

<asp:Content ID="cContent" ContentPlaceHolderID="cphMainContent" runat="server">
    <div id="liens">
        <% foreach (var item in Model) { %>
        <div class="lien <%= (!item.Validation) ? "inValide" : string.Empty %> js-link<%= item.ID %>">
            <% if ((UserType)ViewData["UserType"] == UserType.Administrator){  %>
            <div class="adminTools">
                <%= Html.ActionLinkImage("Editer", "/Design/Images/SiteImages/spacer.gif", "Edit", new { controller = "Liens", ID = item.ID }, new { @class = "editItem" })%>
                <%= Html.ActionLinkImage("Supprimer", "/Design/Images/SiteImages/spacer.gif", "Delete", new { controller = "Liens", ID = item.ID }, new { @class = "deleteItem" })%>
                <% if (!item.Validation){ %>
                    <%= Html.ActionLinkImage("Valider", "/Design/Images/SiteImages/spacer.gif", "Validate", new { controller = "Liens", ID = item.ID }, new { @class = "validateLink" })%>
                <% } %>
            </div>
            <% } %>
            <h1><%= Html.Encode(item.Title) %></h1>
            <div class="desc"><%= Html.Encode(item.Description) %></div>
            <%= Html.ExtrenalLink(item.URL, item.URL, new { rel = "external nofollow" })%>
            <hr class="hr2" />
        </div>
        <% } %>
    </div>
    <div class="hr">&nbsp;</div>
    <%= Html.PagerLinks((int)ViewData["Page"], (int)ViewData["TotalPages"], "Index", new { controller = "Liens" })%>
</asp:Content>
